package com.supermap.dataservice.cloud.push.adv;
import com.alibaba.dubbo.config.annotation.Service;
import com.supermap.dataservice.mysql.config.DynamicDataSourceContextHolder;
import com.supermap.dataservice.util.JSONUtil;
import com.supermap.dataservice.util.JSONUtils;
import com.supermap.dubbo.api.cloud.push.Notice;
import com.supermap.dubbo.api.cloud.push.PushService;
import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * @author aqua
 * @description
 * @date 2018年11月22 下午 3:36
 * @email 1301584033@qq.com
 */
@Service
public class PushServiceImpl implements PushService {

    @Resource
    private PushMapper pushMapper;

    @Override
    public String getProductNoticeTypes(String productId) {
        DynamicDataSourceContextHolder.setDataSourceKey("ds2");
        return pushMapper.getProductNoticeTypes(productId);
    }

    @Override
    public JSONUtil getReceiveuserIdCount(String receiveuserid, String noticetype) {
        DynamicDataSourceContextHolder.setDataSourceKey("ds2");
        return new JSONUtil().setData(pushMapper.getReceiveuserIdCount(receiveuserid,noticetype));
    }

    @Override
    public JSONUtil getGroupReceiveuserIdCount(String receiveuserid, String noticetype) {
        DynamicDataSourceContextHolder.setDataSourceKey("ds2");
        return new JSONUtil().setData(pushMapper.getGroupReceiveuserIdCount(receiveuserid,noticetype));
    }



    @Override
    public List<Map<String, Object>> getNoticetypeReceiveuserIdList(String receiveuserid, String noticetype, Integer pageNum, Integer pageSize) {
        DynamicDataSourceContextHolder.setDataSourceKey("ds2");
        pageNum=(pageNum-1)*pageSize;
        return pushMapper.getNoticetypeReceiveuserIdList(receiveuserid,noticetype,pageNum,pageSize);
    }

    @Override
    public JSONUtil putNoticeRead(Integer noticeId) {
        DynamicDataSourceContextHolder.setDataSourceKey("ds2");
        int count=pushMapper.putNoticeRead(noticeId);
                if(count>0){
                    return  new JSONUtil();
                }
        return new JSONUtil().setCode(100).setIsSuccess(false).setMsg("操作失败");
    }


    @Override
    public void putNotice(Notice notice) {
        DynamicDataSourceContextHolder.setDataSourceKey("ds2");
        pushMapper.putNotice(notice);
    }

    @Override
    public int putNoticeList(List<Notice> noticeList) {
        DynamicDataSourceContextHolder.setDataSourceKey("ds2");
       return  pushMapper.putNoticeList(noticeList);
    }

    @Override
    public JSONUtil putNoticeCode(String code, Integer userId) {
        DynamicDataSourceContextHolder.setDataSourceKey("ds2");
        return new JSONUtil().setData(pushMapper.putNoticeCode(code,userId));
    }

    @Override
    public String getNoticeCodeByUserId(Integer userId) {
        DynamicDataSourceContextHolder.setDataSourceKey("ds2");
        return pushMapper.getNoticeCodeByUserId(userId);
    }

    @Override
    public String getNoticeObjectUseridList(Integer receiveuserid, Integer noticetype) {
        DynamicDataSourceContextHolder.setDataSourceKey("ds2");
        return pushMapper.getNoticeObjectUseridList(receiveuserid,noticetype);
    }

    @Override
    public List<String> getAllUserIdByAreaCode(String areaCode) {
        DynamicDataSourceContextHolder.setDataSourceKey("ds2");
       return pushMapper.getAllUserIdByAreaCode(areaCode);

    }

    @Override
    public List<String> getUserCode(String users) {
        DynamicDataSourceContextHolder.setDataSourceKey("ds2");
        return pushMapper.getUserCode(users);
    }

    @Override
    public JSONUtils getNoticeList(String noticetype, String userId, Integer pageSize) {
        DynamicDataSourceContextHolder.setDataSourceKey("ds2");
        return new JSONUtils().setData(pushMapper.getNoticeList(noticetype,userId,pageSize));
    }


}
